1.進入容器
? ? docker exec -it redis-node-1 /bin/bash
? ??
2.#注意,進入docker容器后才能執(zhí)行一下命令,且注意自己的真實IP地址
? ? redis-cli --cluster create IP地址:6381 IP地址:6382 ? ? ? ? ? ? ? ?IP地址:6383 192.168.111.147:6384 IP地址:6385 ? ? ? ?IP地址:6386 --cluster-replicas 1
? ? #--cluster-replicas 1 表示為每個master創(chuàng)建一個slave節(jié)點
? ??
3.#3主3從搞定
運行結果
[root@localhost home]# docker exec -it redis-node-1 /bin/bash
root@localhost:/data# redis-cli --cluster create 192.168.153.138:6381 192.168.153.138:6382 192.168.153.138:6383 192.168.153.138:6384 192.168.153.138:6385 ? ?192.168.153.138:6386 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes... #hash槽對這六個節(jié)點經行分配
Master[0] -> Slots 0 - 5460 #如上圖對16384個槽位分配 0 - 5460 5461 - 10922 10923 - 16383
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.153.138:6385 to 192.168.153.138:6381
Adding replica 192.168.153.138:6386 to 192.168.153.138:6382
Adding replica 192.168.153.138:6384 to 192.168.153.138:6383
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: d9b335b44e89e3a46f30466e70867de7fdd3d5ad 192.168.153.138:6381 #主
? ?slots:[0-5460] (5461 slots) master
M: 7a876fd455a6e77923e0ab340335c430f25ed11f 192.168.153.138:6382 #主
? ?slots:[5461-10922] (5462 slots) master
M: fbacfaed169736db5278e4f685adf44a9bcd55ea 192.168.153.138:6383 #主
? ?slots:[10923-16383] (5461 slots) master
S: 798440dfeb0aa728aba2f4a9f783eb20edeaa09c 192.168.153.138:6384 #從
? ?replicates fbacfaed169736db5278e4f685adf44a9bcd55ea
S: 37299c5efbf061f019bf24780661144a171c24df 192.168.153.138:6385 #從
? ?replicates d9b335b44e89e3a46f30466e70867de7fdd3d5ad
S: ece2d11584c4d7a0b1d9699c90aa2016fcf75924 192.168.153.138:6386 #從
? ?replicates 7a876fd455a6e77923e0ab340335c430f25ed11f
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
.
>>> Performing Cluster Check (using node 192.168.153.138:6381)
M: d9b335b44e89e3a46f30466e70867de7fdd3d5ad 192.168.153.138:6381
? ?slots:[0-5460] (5461 slots) master
? ?1 additional replica(s)
S: ece2d11584c4d7a0b1d9699c90aa2016fcf75924 192.168.153.138:6386
? ?slots: (0 slots) slave
? ?replicates 7a876fd455a6e77923e0ab340335c430f25ed11f
M: fbacfaed169736db5278e4f685adf44a9bcd55ea 192.168.153.138:6383
? ?slots:[10923-16383] (5461 slots) master
? ?1 additional replica(s)
M: 7a876fd455a6e77923e0ab340335c430f25ed11f 192.168.153.138:6382
? ?slots:[5461-10922] (5462 slots) master
? ?1 additional replica(s)
S: 37299c5efbf061f019bf24780661144a171c24df 192.168.153.138:6385
? ?slots: (0 slots) slave
? ?replicates d9b335b44e89e3a46f30466e70867de7fdd3d5ad
S: 798440dfeb0aa728aba2f4a9f783eb20edeaa09c 192.168.153.138:6384
? ?slots: (0 slots) slave
? ?replicates fbacfaed169736db5278e4f685adf44a9bcd55ea
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.